package org.tang.stock;

public class Stock {
	private int id;
	private String date;
	private int openPrice;
	private int closePrice;
	private int hightPrice;
	private int lowPrice;
	private long volume;
	private int adjClosePrice;

	public Stock(String line)throws Exception{
		String []cells = line.split(",");
		if(cells.length != 7){
			throw new Exception();
		}

		this.date = cells[0];
		this.openPrice = (int)(Float.parseFloat(cells[1]) * 100);
		this.hightPrice = (int)(Float.parseFloat(cells[2]) * 100);
		this.lowPrice = (int)(Float.parseFloat(cells[3]) * 100);
		this.closePrice = (int)(Float.parseFloat(cells[4]) * 100);
		this.volume = Long.parseLong(cells[5])/100;
		this.adjClosePrice = (int)(Float.parseFloat(cells[6]) * 100);
	}

	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public int getOpenPrice() {
		return openPrice;
	}
	public void setOpenPrice(int openPrice) {
		this.openPrice = openPrice;
	}
	public int getClosePrice() {
		return closePrice;
	}
	public void setClosePrice(int closePrice) {
		this.closePrice = closePrice;
	}
	public int getHightPrice() {
		return hightPrice;
	}
	public void setHightPrice(int hightPrice) {
		this.hightPrice = hightPrice;
	}
	public int getLowPrice() {
		return lowPrice;
	}
	public void setLowPrice(int lowPrice) {
		this.lowPrice = lowPrice;
	}
	public long getVolume() {
		return volume;
	}
	public void setVolume(long volume) {
		this.volume = volume;
	}
	public int getAdjClosePrice() {
		return adjClosePrice;
	}
	public void setAdjClosePrice(int adjClosePrice) {
		this.adjClosePrice = adjClosePrice;
	}

	@Override
	public String toString() {

		return this.date+","
		+ (this.openPrice*1.0)/100 + ","
		+ (this.hightPrice*1.0)/100 + ","
		+ (this.lowPrice*1.0)/100 + ","
		+ (this.closePrice*1.0)/100 + ","
		+ this.volume*100 + ","
		+ (this.adjClosePrice*1.0)/100;
	}
	public final static int RED_HIGH_LOW  = 1;
	public final static int RED_HIGH  = 2;
	public final static int RED_LOW = 3;
	public final static int RED = 4;

	public final static int BLUE_HIGH_LOW  = 5;
	public final static int BLUE_HIGH  = 6;
	public final static int BLUE_LOW = 7;
	public final static int BLUE = 8;

	public final static int HIGH_LOW  = 9;
	public final static int HIGH  = 10;
	public final static int LOW = 11;
	public final static int EQUAL = 12;
	public int getType(){
		if(this.openPrice < this.closePrice){
			if(this.hightPrice > this.closePrice && this.openPrice > this.lowPrice)
				return RED_HIGH_LOW;
			else if(this.hightPrice > this.closePrice && this.openPrice == this.lowPrice)
				return RED_HIGH;
			else if(this.hightPrice == this.closePrice && this.openPrice > this.lowPrice)
				return RED_LOW;
			else if(this.hightPrice == this.closePrice && this.openPrice == this.lowPrice)
				return RED;
		}else if(this.openPrice > this.closePrice){
			if(this.hightPrice > this.openPrice && this.closePrice > this.lowPrice)
				return BLUE_HIGH_LOW;
			else if(this.hightPrice > this.openPrice && this.closePrice == this.lowPrice)
				return BLUE_HIGH;
			else if(this.hightPrice == this.openPrice && this.closePrice > this.lowPrice)
				return BLUE_LOW;
			else if(this.hightPrice == this.openPrice && this.closePrice == this.lowPrice)
				return BLUE;
		}else{
			if(this.hightPrice > this.openPrice && this.closePrice > this.lowPrice)
				return HIGH_LOW;
			else if(this.hightPrice > this.openPrice)
				return HIGH;
			else if(this.openPrice > this.lowPrice)
				return LOW;
			else
				return EQUAL;
		}
		return 0;
	}

}
